home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ecstr3.arc / STRXNMOV.C < prev    next >
C/C++ Source or Header  |  1987-03-04  |  2KB  |  48 lines

  1. /*  File   : strxnmov.c
  2.     Author : Richard A. O'Keefe.
  3.     Updated: 2 June 1984
  4.     Defines: strxnmov()
  5.  
  6.     strxnmov(dst, len, src1, ..., srcn, NullS)
  7.     moves the first len characters of the concatenation of src1,...,srcn
  8.     to dst.  If there aren't that many characters, a NUL character will
  9.     be added to the end of dst to terminate it properly.  This gives the
  10.     same effect as calling strxcpy(buff, src1, ..., srcn, NullS) with a
  11.     large enough buffer, and then calling strnmov(dst, buff, len).
  12.     It is just like strnmov except that it concatenates multiple sources.
  13.     Beware: the last argument should be the null character pointer.
  14.     Take VERY great care not to omit it!  Also be careful to use NullS
  15.     and NOT to use 0, as on some machines 0 is not the same size as a
  16.     character pointer, or not the same bit pattern as NullS.
  17.  
  18.     Note: strxnmov is like strnmov in that it always moves EXACTLY len
  19.     characters; dst will be padded on the right with NUL characters as
  20.     needed.  strxncpy does the same.  strxncat, like strncat, does NOT.
  21. */
  22.  
  23. #include "strings.h"
  24. #include <varargs.h>
  25.  
  26. /*VARARGS*/
  27. char *strxnmov(va_alist)
  28.     va_dcl
  29.     {
  30.        va_list pvar;
  31.        register char *dst, *src;
  32.        register int len;
  33.  
  34.        va_start(pvar);
  35.        dst = va_arg(pvar, char *);
  36.        len = va_arg(pvar, int);
  37.        src = va_arg(pvar, char *);
  38.        while (src != NullS) {
  39.            do if (--len < 0) return dst;
  40.            while (*dst++ = *src++);
  41.          dst--;
  42.            src = va_arg(pvar, char *);
  43.        }
  44.        for (src = dst; --len >= 0; *dst++ = NUL) ;
  45.        return src;
  46.     }
  47.  
  48.